import React, { Component } from 'react'
import request from '../untils/request'

export default class Register extends Component {
    state={
        phone:'',
        pwd:''
    }
    render() {
        return (
            <div>
                <input type="text" name='phone' placeholder='用户名' onChange={(e)=>{this.setState({phone:e.target.value})}}/>
                <input type="text" name='pwd' placeholder='密码' onChange={(e)=>{this.setState({pwd:e.target.value})}}/>
                <button onClick={this.handReg}>注册</button>
            </div>
        )
    }

    //注册
    handReg=async ()=>{
       let {phone,pwd}=this.state;
       let res=await request.post('/register',{phone,pwd})
       //console.log(res);
       //返回信息给前台
       alert(res.data.msg)
       if(res.data.code===0){
           this.props.history.push('/login')
       }
    }

}
